package com.devmindset.legoframework.usage.client.component;

import java.util.Date;

import com.devmindset.legoframework.client.mvc.LegoComponent;
import com.devmindset.legoframework.client.mvc.LegoModel;
import com.devmindset.legoframework.client.mvc.metadata.ComponentStory;
import com.devmindset.legoframework.client.mvc.metadata.Stories;
import com.devmindset.legoframework.usage.client.event.Events;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.calendar.Calendar;
import com.smartgwt.client.widgets.calendar.CalendarEvent;

public class CalendarComponent extends LegoComponent {

	/** {@inheritDoc} */
	@Override
	public Canvas construct(LegoModel model) {
		Calendar calendar = new Calendar() {
			//java.util.Calendar not available on client-side
			@SuppressWarnings("deprecation")
			protected String getDayBodyHTML(Date date, CalendarEvent[] events,
					Calendar calendar, int rowNum, int colNum) {
				String returnStr = date.getDate() + "";
				Date d = new Date();
				if (date.getDate() == d.getDate() && date.getYear() == d.getYear() && date.getMonth() == d.getMonth()) {
					returnStr = "<b><i>" + returnStr + "</i></b>";
				}
				return returnStr;
			}
		};
		
		calendar.setWidth100();
		calendar.setHeight100();
		calendar.setShowDayView(false);
		calendar.setShowWeekView(false);
		calendar.setShowOtherDays(false);
		calendar.setShowDayHeaders(false);
		calendar.setShowDatePickerButton(false);
		calendar.setShowEdges(true);
		calendar.setShowOtherDays(true);
		calendar.setShowAddEventButton(false);
		calendar.setDisableWeekends(false);
		calendar.setShowDateChooser(false);
		calendar.setCanCreateEvents(false);
		calendar.draw();

		return calendar;
	}

	/** {@inheritDoc} */
	@Override
	public void calculate(LegoModel model) {
		// nothing to additionally calculate for this component
	}

	/** {@inheritDoc} */
	public ComponentStory myStory() {
		return Stories.component()
			.constructedBy(Events.RENDER_CALENDAR_COMPONENT)
			.knownAs("Compact Calendar Component");
	}

}